package com.stgy.lease.web.admin.controller.system;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.stgy.lease.common.result.Result;
import com.stgy.lease.model.domain.SystemPost;
import com.stgy.lease.model.domain.SystemUser;
import com.stgy.lease.web.admin.dto.BaseSearchDto;
import com.stgy.lease.web.admin.service.SystemPostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName:PostController
 * Package:com.stgy.lease.web.admin.controller.system
 * Description:
 *
 * @Author:helei
 * @Create:2024/9/3 - 14:48
 */
@RestController
@RequestMapping("/admin/system/post")
@Tag(name = "岗位管理")
public class PostController {

    @Autowired
    private SystemPostService systemPostService;

    //http://localhost:5174/admin/system/post/page?current=1&size=10 GET
    @Operation(summary = "分页查询岗位列表")
    @GetMapping("/page")
    public Result<Page<SystemPost>> page(BaseSearchDto searchDto) {
        return Result.ok(systemPostService.page(searchDto.getPage(SystemPost.class)));
    }

    @Operation(summary = "新增或更新岗位")
    @PostMapping("/saveOrUpdate")
    public Result<String> saveOrUpdate(@RequestBody SystemPost systemPost) {
        return Result.build(systemPostService.saveOrUpdate(systemPost));
    }

    //http://localhost:5174/admin/system/post/list GET
    @Operation(summary = "查询所有岗位列表")
    @GetMapping("/list")
    public Result<List<SystemPost>> list() {
        return Result.ok(systemPostService.list());
    }

    //http://localhost:5174/admin/system/post/updateStatusByPostId?id=1&status=1 POST
    @Operation(summary = "根据id更新岗位状态")
    @PostMapping("/updateStatusByPostId")
    public Result<String> updateStatusByPostId(@RequestParam Long id, @RequestParam Integer status) {
        return Result.build(systemPostService.update(Wrappers.lambdaUpdate(SystemPost.class)
                .ge(SystemPost::getId, id)
                .set(SystemPost::getStatus, status)));
    }

    //http://localhost:5174/admin/system/post/deleteById?id=1830862229659049985 DELETE
    @Operation(summary = "根据id删除岗位")
    @DeleteMapping("/deleteById")
    public Result<String> deleteById(@RequestParam Long id) {
        return Result.build(systemPostService.removeById(id));
    }
}
